{extend name="base" /}
{block name="header"}
<style>
    .form-control { height:40px; line-height:40px;}
    .container {padding: 0px 5px}
    .outer_sites
    {
        line-height: 1.5; margin-left:0px; border:solid 0px red; padding-left:0px;
    }
    .outer_sites li
    {
        float: left;
        width: 148px;
        height:34px;
        overflow:hidden;
        line-height:34px;
        margin-top: 5px;
    }
    .col-sm-10 {
        padding-right: 8px ;
    }
</style>
{/block}
{block name="body"}
<div class="container" style="margin-top: 20px">
    <div class="login">
        <div class="form-group">
            <div class="col-sm-10">
                <input name="phone" type="text" class="form-control login-phone" placeholder="请输入手机号">
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-10">
                <input  style="width: 70%;float: left" name="code" type="text" class="form-control code" placeholder="请输入验证码">
                &nbsp;
                <input id="TencentCaptcha" data-appid="2028880981" data-cbfn="callback" style="width: 28%;float: right;position: absolute;top: -32px; height:45px; line-height:45px; padding:0 0;" type="button"  value="获取验证码" class="btn btn-primary btn-lg">
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="text-center col-sm-10">
            <input type="submit" name="login" value="登陆" class="btn btn-primary btn-lg login-btn" style="width:100%; height:45px; line-height:45px; padding:0 0;">
        </div>
    </div>
</div>
<!--<div class="container" style="margin-top: 18px; padding-left:20px;">-->
<!--    <div class="form-group">-->
<!--        <ul class="fix outer_sites">-->
<!--            <li><a href="javascript:void(0)" style="cursor: pointer" onclick="toWeixinLogin()" id="A4"><img src="__IMAGES__/weixin_2f.png" align="absmiddle" height="32" width="32" alt="微信登录"> 微信登录</a></li><li>-->
<!--        </ul>-->
<!--    </div>-->
<!--</div>-->
{/block}
{block name="footer"}
<script src="https://ssl.captcha.qq.com/TCaptcha.js"></script>

<script>
    $(function (){

        // 获取验证码
        $(".login-btn").on("click",function() {

            var phone = $(".login-phone").val();
            var code = $(".code").val();
            if (phone.length != 11)
            {
                layer.msg("手机号码不正确");
                return false;
            }
            if (code.length == 0)
            {
                layer.msg("验证码未填写");
                return false;
            }

            $.ajax({
                type: "POST",
                url: "/user/login",
                data: {
                    'phone' : phone,
                    'code' : code
                },
                dataType: "json",
                success: function(res) {
                    if (res.code == 200) {
                        location.href = '/user';
                    }
                }
            })
        });

        // 登录回调
        window.callback = function(res){
            var loginPhone = $(".login-phone").val();
            if (loginPhone.length != 11)
            {
                layer.msg("手机号码不正确");
                return false;
            }

            if(res.ret === 0){
                $.ajax({
                    type: "POST",
                    url: "/send_code",
                    data : {
                        'ticket' : res.ticket,
                        'randstr' : res.randstr,
                        'phone' : loginPhone
                    },
                    dataType: "json",
                    success: function(t) {
                    }
                })
            }
        }

    });
</script>
{/block}